#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int find(int father[], int x)
{
	return father[x] == x ? x : father[x] = find(father, father[x]);
}

int merge(int father[], int x, int y)
{
	int fx = find(father, x);
	int fy = find(father, y);
	if (fx == fy) {
		return 0;
	}
	father[fx] = fy;
	return 1;
}

int main()
{
	int n, m;
	cin >> n >> m;

        int father[40005]; 
	for (int i = 0; i <= n * n; i++) {
		father[i] = i;
	}

	int x, y, p1, p2, step = 0;
	char ch;
	for (int i = 0; i < m; i++) {
		cin >> x >> y >> ch;
		p1 = (x - 1) * n + y;
		if (ch == 'D') {
			x += 1;
		} else {
			y += 1;
		}
		p2 = (x - 1) * n + y;

		step++;
		if (!merge(father, p1, p2)) {
                        cout<<step<<endl;
                        return 0;
		}
	}

        cout<<"draw"<<endl;
        return 0;
}